<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateDonatesTable extends Migration
{
	private $tableName = 'donates';
	private $tableComment = '众筹捐赠表';
	private $primaryKey = 'id';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function (Blueprint $table) {
			$table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('兑换id');
            $table->string('title', 50)->comment('众筹主题');
            $table->string('donate_openid',50)->comment('捐赠者openid')->nullable();
			$table->string('doante_nickname', 500)->comment('捐赠者昵称')->nullable();
			$table->string('doante_avatar', 500)->comment('捐赠者头像')->nullable();
			$table->string('donate_sn',20)->comment('捐赠编号')->default(0);
			$table->string('order_sn',20)->comment('求助者订单编号')->nullable();
			$table->string('order_id',10)->comment('求助者订单id')->nullable();
			$table->string('openid',10)->comment('众筹者openid')->nullable();
			$table->string('nickname',50)->comment('众筹者昵称')->nullable();
			$table->string('total',10)->comment('捐款金额')->default(0);
			$table->unsignedTinyInteger('status')->comment('状态，1进行中,2退款，3待支付，4完成')->default(1);
			$table->string('num',10)->comment('支持者人数')->default(0);
            $table->timestamps();
			if (env('DB_CONNECTION') == 'oracle') {
				$table->comment = $this->tableComment;
			}
		});

		if (env('DB_CONNECTION') == 'mysql') {
			DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists($this->tableName);
		if (env('DB_CONNECTION') == 'oracle') {
			$sequence = DB::getSequence();
			$sequence->drop(strtoupper($this->tableName . '_' . $this->primaryKey . '_SEQ'));
		}
	}
}
